//
//  ScanViewController.m
//  VPPublicUntilitisForPod
//
//  Created by vernepung on 2017/6/13.
//  Copyright © 2017年 vernepung. All rights reserved.
//

#import "ScanViewController.h"
#import "VPScanQrCodeView.h"
#import "UtilsMacro.h"

@interface ScanViewController ()<VPScanQrCodeViewDelegate>
@property (strong, nonatomic)  VPScanQrCodeView *codeView;
@end

@implementation ScanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat padding = (kMainBoundsWidth - 240 * (kMainBoundsHeight / 750.f)) / 2.f;
    CGRect frame = CGRectMake(0, 0, kMainBoundsWidth, kMainBoundsHeight);
    
    self.codeView = [[VPScanQrCodeView alloc]initWithFrame:frame maskViewWidth:kMainBoundsWidth - padding * 2 maskBorderColor:[UIColor redColor] tintColor:[UIColor greenColor] andNavHeight:64];
    // [[VPScanQrCodeView alloc]initWithFrame:frame andMaskViewWidth:kMainBoundsWidth - padding * 2 andBorderColor:[UIColor redColor]];
    self.codeView.delegate = self;
    [self.view addSubview:self.codeView];
    // Do any additional setup after loading the view.
    [self showProgressViewWithTitle:@"正在加载摄像头..."];
}

- (void)setupViews {
    self.title = @"扫码签到";
}

#pragma mark - TSScanQrCodeViewDelegate
- (void)vpScanQrCodeCompletedWithResult:(NSString *)result {
    static NSInteger i = 0;
    i ++;
    self.title = [NSString stringWithFormat:@"%zd",i];
    [self handleScanCodeResult:result];
    DLog(@"%@",result);
}

- (void)handleScanCodeResult:(NSString *)result {
}

- (void)vpScanQrCodeWithError:(VPQrCodeError *)error {
    DLog(@"vpScanQrCodeWithError");
}

- (void)vpCaptureRunningCompleted {
    [self hideProgressView];
    [self.codeView startScanQrCode];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
